# -*- UTF-8 -*-
import pandas as pd
import matplotlib.pyplot as plt


def plot_trend(csv_path, tag_list):
    df = pd.read_csv(csv_path)

    for tag_name in tag_list:
        tags_count_percentage = []
        row_tags_sum = df['row_tags_sum']
        for index, val in enumerate(df[tag_name]):
            # sum = sum + val
            tags_count_percentage.append(val / row_tags_sum[index])
        # period = pd.period_range(start="2008-08", end="2018-08", freq='M')
        # 设置时间标签显示格式
        plt.plot(df['periods'], tags_count_percentage, marker="o", label=tag_name)

    plt.ylabel('% of Stack Overflow Tags that month')
    plt.xticks(rotation=90)
    plt.title("Tags Trends")
    # 显示图例
    plt.legend()
    plt.show()


if __name__ == '__main__':
    tag_name_list = ["c", "java", "python", "c#"]
    plot_trend("tags_trend_new.csv", tag_name_list)

